package com.codegeek.project.slope.controller;

import com.codegeek.common.utils.poi.ExcelUtil;
import com.codegeek.framework.aspectj.lang.annotation.Log;
import com.codegeek.framework.aspectj.lang.enums.BusinessType;
import com.codegeek.framework.web.controller.BaseController;
import com.codegeek.framework.web.domain.AjaxResult;
import com.codegeek.framework.web.page.TableDataInfo;
import com.codegeek.project.slope.domain.SlopeTarget;
import com.codegeek.project.slope.service.ISlopeTargetService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 监测目标Controller
 *
 * @author codegeek
 * @date 2020-02-17
 */
@RestController
@RequestMapping("/slope/target")
@Api(value = "监测目标Controller", tags = {"监测目标操作接口"})
public class SlopeTargetController extends BaseController {
    @Autowired
    private ISlopeTargetService slopeTargetService;

    /**
     * 查询监测目标列表
     */
    @ApiOperation("查询监测目标列表")
    @GetMapping("/list")
    public TableDataInfo list(SlopeTarget slopeTarget) {
        startPage();
        List<SlopeTarget> list = slopeTargetService.selectSlopeTargetList(slopeTarget);
        return getDataTable(list);
    }

    /**
     * 导出监测目标列表
     */
    @ApiOperation("导出监测目标列表")
    @Log(title = "设备管理", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(SlopeTarget slopeTarget) {
        List<SlopeTarget> list = slopeTargetService.selectSlopeTargetList(slopeTarget);
        ExcelUtil<SlopeTarget> util = new ExcelUtil<SlopeTarget>(SlopeTarget.class);
        return util.exportExcel(list, "target");
    }

    /**
     * 获取监测目标详细信息
     */
    @ApiOperation("获取监测目标详细信息")
    @GetMapping(value = "/getInfo/{targetId}")
    public AjaxResult getInfo(@PathVariable("targetId") Long targetId) {
        return AjaxResult.success(slopeTargetService.selectSlopeTargetById(targetId));
    }

    /**
     * 新增监测目标
     */
    @ApiOperation("新增监测目标")
    @Log(title = "设备管理", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    public AjaxResult add(@RequestBody SlopeTarget slopeTarget) {
        return toAjax(slopeTargetService.insertSlopeTarget(slopeTarget));
    }

    /**
     * 修改监测目标
     */
    @ApiOperation("修改监测目标")
    @Log(title = "设备管理", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    public AjaxResult edit(@RequestBody SlopeTarget slopeTarget) {
        return toAjax(slopeTargetService.updateSlopeTarget(slopeTarget));
    }

    /**
     * 删除监测目标
     */
    @ApiOperation("删除监测目标")
    @Log(title = "设备管理", businessType = BusinessType.DELETE)
    @PostMapping("/remove/{targetIds}")
    public AjaxResult remove(@PathVariable Long[] targetIds) {
        return toAjax(slopeTargetService.deleteSlopeTargetByIds(targetIds));
    }
}
